using JRO;
using System;
using System.Collections;
using System.Data.OleDb;
using System.IO;
internal class EventUtil
{
	public OleDbCommand oleDbCommand_0;
	private OleDbConnection oleDbConnection_0;
	private string string_0;
	public EventUtil()
	{
		this.string_0 = Directory.GetCurrentDirectory();
		this.method_0();
	}
	public EventUtil(string string_1)
	{
		this.string_0 = Directory.GetCurrentDirectory();
		this.method_1(string_1);
	}
	public void method_0()
	{
		if (this.oleDbConnection_0 == null)
		{
			string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=" + this.string_0 + "\\config\\鹊桥数据.mdb;Jet OLEDB:Database Password=brdg{&}246";
			this.oleDbConnection_0 = new OleDbConnection(connectionString);
			this.oleDbConnection_0.Open();
		}
	}
	public void method_1(string string_1)
	{
		if (this.oleDbConnection_0 == null)
		{
			string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=" + string_1;
			this.oleDbConnection_0 = new OleDbConnection(connectionString);
			this.oleDbConnection_0.Open();
		}
	}
	public bool method_10(EventItem eventItem, out string string_1)
	{
		bool result;
		try
		{
			string text = "INSERT INTO bridgeinfo(eventId, startTime, endTime, avgCommission, shareRate) VALUES ('{eventId}',{startTime},{endTime},{avgCommission},{shareRate});";
			new OleDbCommand(text.Replace("{eventId}", eventItem.event_id).Replace("{startTime}", string.Concat(eventItem.start_time)).Replace("{endTime}", string.Concat(eventItem.end_time)).Replace("{avgCommission}", string.Concat(eventItem.avg_commission)).Replace("{shareRate}", string.Concat(eventItem.share_rate)), this.oleDbConnection_0).ExecuteNonQuery();
			string_1 = "";
			result = true;
		}
		catch (Exception ex)
		{
			string_1 = "出错啦！" + ex.ToString();
			result = false;
		}
		return result;
	}
	public ArrayList method_11(string string_1, out string string_2)
	{
		string sql = "select * from bridgeinfo where eventId='" + string_1 + "'";
		return this.query_event(sql, out string_2);
	}
	public ArrayList query_event(string sql, out string string_2)
	{
		ArrayList result;
		try
		{
			ArrayList arrayList = new ArrayList();
			OleDbDataReader oleDbDataReader = new OleDbCommand(sql, this.oleDbConnection_0).ExecuteReader();
			while (oleDbDataReader.Read())
			{
				arrayList.Add(new EventItem
				{
					beid = int.Parse(oleDbDataReader["beid"].ToString()),
					event_id = oleDbDataReader["eventId"].ToString(),
					start_time = int.Parse(oleDbDataReader["startTime"].ToString()),
					end_time = int.Parse(oleDbDataReader["endTime"].ToString()),
					avg_commission = double.Parse(oleDbDataReader["avgCommission"].ToString()),
					share_rate = double.Parse(oleDbDataReader["shareRate"].ToString())
				});
			}
			string_2 = "";
			oleDbDataReader.Close();
			result = arrayList;
		}
		catch (Exception ex)
		{
			string_2 = "出错啦：" + ex.ToString();
			result = new ArrayList();
		}
		return result;
	}
	public ArrayList method_13(string event_ids, out string string_2)
	{
		ArrayList result;
		try
		{
			string str = "'" + event_ids.Replace(",", "', '") + "'";
			string cmdText = "select eventId from bridgeinfo where eventId in (" + str + ");";
			ArrayList arrayList = new ArrayList();
			OleDbDataReader oleDbDataReader = new OleDbCommand(cmdText, this.oleDbConnection_0).ExecuteReader();
			while (oleDbDataReader.Read())
			{
				arrayList.Add(oleDbDataReader["eventId"].ToString());
			}
			string_2 = "";
			oleDbDataReader.Close();
			result = arrayList;
		}
		catch (Exception ex)
		{
			string_2 = "出错啦：" + ex.ToString();
			result = new ArrayList();
		}
		return result;
	}
	public bool method_14(string string_1, out string string_2)
	{
		bool result;
		try
		{
			new OleDbCommand(string_1, this.oleDbConnection_0).ExecuteNonQuery();
			string_2 = "";
			result = true;
		}
		catch (Exception ex)
		{
			string_2 = "出错啦：" + ex.ToString();
			result = false;
		}
		return result;
	}
	public bool method_15(out string string_1)
	{
		try
		{
			int num = 0;
			int num2 = 0;
			string cmdText = "select count(movflg) as movflgcnt from bridgeitem where movflg=1;";
			OleDbDataReader oleDbDataReader = new OleDbCommand(cmdText, this.oleDbConnection_0).ExecuteReader();
			if (oleDbDataReader.Read())
			{
				num = int.Parse(oleDbDataReader["movflgcnt"].ToString());
			}
			cmdText = "select count(*) as allcnt from bridgeitem;";
			oleDbDataReader = new OleDbCommand(cmdText, this.oleDbConnection_0).ExecuteReader();
			if (oleDbDataReader.Read())
			{
				num2 = int.Parse(oleDbDataReader["allcnt"].ToString());
			}
			int num3 = 0;
			int num4 = 0;
			cmdText = "select count(movflg) as movflgcnt from bridgeinfo where movflg=1;";
			oleDbDataReader = new OleDbCommand(cmdText, this.oleDbConnection_0).ExecuteReader();
			if (oleDbDataReader.Read())
			{
				num3 = int.Parse(oleDbDataReader["movflgcnt"].ToString());
			}
			cmdText = "select count(*) as allcnt from bridgeinfo;";
			oleDbDataReader = new OleDbCommand(cmdText, this.oleDbConnection_0).ExecuteReader();
			if (oleDbDataReader.Read())
			{
				num4 = int.Parse(oleDbDataReader["allcnt"].ToString());
			}
			if (num == num2 && num3 == num4)
			{
				string_1 = "";
				return true;
			}
		}
		catch
		{
			string string_2 = "alter table bridgeitem add movflg int not null";
			this.method_14(string_2, out string_1);
			string_2 = "alter table bridgeinfo add movflg int not null";
			this.method_14(string_2, out string_1);
		}
		string_1 = "";
		return false;
	}
	public ArrayList method_16()
	{
		ArrayList result;
		try
		{
			ArrayList arrayList = new ArrayList();
			string text = "select distinct eventId from bridgeitem where movflg<>1 or movflg is null;";
			if (this.oleDbCommand_0 == null)
			{
				this.oleDbCommand_0 = new OleDbCommand(text, this.oleDbConnection_0);
			}
			else
			{
				this.oleDbCommand_0.CommandText = text;
			}
			OleDbDataReader oleDbDataReader = this.oleDbCommand_0.ExecuteReader();
			while (oleDbDataReader.Read())
			{
				arrayList.Add(oleDbDataReader["eventId"].ToString());
			}
			oleDbDataReader.Close();
			oleDbDataReader.Dispose();
			result = arrayList;
		}
		catch (Exception)
		{
			result = new ArrayList();
		}
		return result;
	}
	public void method_17()
	{
		string text = this.string_0 + "\\config\\鹊桥数据.mdb";
		if (!File.Exists(text))
		{
			throw new Exception("目标数据库不存在,无法压缩");
		}
		try
		{
			if (this.oleDbConnection_0 != null)
			{
				this.oleDbConnection_0.Close();
				this.oleDbConnection_0.Dispose();
				this.oleDbConnection_0 = null;
			}
			string text2 = "alibrdg" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".bak";
			text2 = text.Substring(0, text.LastIndexOf("\\") + 1) + text2;
			string destconnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + text2 + ";Jet OLEDB:Database Password=brdg{&}246";
			string sourceConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + text + ";Jet OLEDB:Database Password=brdg{&}246";
			new JetEngineClass().CompactDatabase(sourceConnection, destconnection);
			File.Copy(text2, text, true);
			File.Delete(text2);
		}
		catch
		{
		}
		finally
		{
			this.method_0();
		}
	}
	public bool createEventGoods(EventGoods event_goods, out string string_1)
	{
		bool result;
		try
		{
			string text = "INSERT INTO bridgeitem(eventId, itemId, itemTitle, sellerId,  commissionRate, isSoldOut, discountPrice, auctionPrice, discountRate, soldQuantity, mall, actCmsRate, actEarn, excellence, startTime) VALUES ('{eventId}','{itemId}','{itemTitle}', '{sellerId}',{commissionRate},{isSoldOut},{discountPrice},'{auctionPrice}','{discountRate}',{soldQuantity},{mall},{actCmsRate},{actEarn},{excellence},{startTime});";
			new OleDbCommand(text.Replace("{eventId}", event_goods.event_id).Replace("{itemId}", event_goods.num_iid).Replace("{itemTitle}", event_goods.title.Replace("'", "")).Replace("{sellerId}", event_goods.user_num_id).Replace("{commissionRate}", string.Concat(event_goods.commission_rate)).Replace("{isSoldOut}", string.Concat(event_goods.is_sold_out)).Replace("{discountPrice}", string.Concat(event_goods.price)).Replace("{auctionPrice}", event_goods.ori_price ?? "").Replace("{discountRate}", event_goods.discount_rate).Replace("{soldQuantity}", string.Concat(event_goods.volume)).Replace("{mall}", string.Concat(event_goods.is_mall)).Replace("{actCmsRate}", string.Concat(event_goods.actCmsRate)).Replace("{actEarn}", string.Concat(event_goods.actEarn)).Replace("{excellence}", string.Concat(event_goods.excellence)).Replace("{startTime}", string.Concat(event_goods.startTime)), this.oleDbConnection_0).ExecuteNonQuery();
			string_1 = "";
			result = true;
		}
		catch (Exception ex)
		{
			string_1 = "出错啦！" + ex.ToString();
			result = false;
		}
		return result;
	}
	public ArrayList method_3(string string_1, string string_2, out string string_3)
	{
		string string_4 = "select * from bridgeitem where itemTitle like '%" + string_1 + "%' " + string_2;
		return this.method_7(string_4, out string_3);
	}
	public ArrayList method_4(string string_1, string string_2, out string string_3)
	{
		string string_4 = "select * from bridgeitem where eventId='" + string_1 + "' " + string_2;
		return this.method_7(string_4, out string_3);
	}
	public ArrayList method_5(string string_1, string string_2, out string string_3)
	{
		string string_4 = "select * from bridgeitem where itemId='" + string_1 + "' " + string_2;
		return this.method_7(string_4, out string_3);
	}
	public ArrayList method_6(string string_1, string string_2, out string string_3)
	{
		string string_4 = string.Concat(new string[]
		{
			"select * from bridgeitem where eventId='",
			string_1,
			"' and itemId='",
			string_2,
			"'"
		});
		return this.method_7(string_4, out string_3);
	}
	public ArrayList method_7(string string_1, out string string_2)
	{
		ArrayList result;
		try
		{
			ArrayList arrayList = new ArrayList();
			OleDbDataReader oleDbDataReader = new OleDbCommand(string_1, this.oleDbConnection_0).ExecuteReader();
			while (oleDbDataReader.Read())
			{
				arrayList.Add(new EventGoods
				{
					biid = int.Parse(oleDbDataReader["biid"].ToString()),
					event_id = oleDbDataReader["eventId"].ToString(),
					num_iid = oleDbDataReader["itemId"].ToString(),
					title = oleDbDataReader["itemTitle"].ToString(),
					user_num_id = oleDbDataReader["sellerId"].ToString(),
					commission_rate = double.Parse(oleDbDataReader["commissionRate"].ToString()),
					is_sold_out = int.Parse(oleDbDataReader["isSoldOut"].ToString()),
					price = double.Parse(oleDbDataReader["discountPrice"].ToString()),
					ori_price = oleDbDataReader["auctionPrice"].ToString(),
					discount_rate = oleDbDataReader["discountRate"].ToString(),
					volume = int.Parse(oleDbDataReader["soldQuantity"].ToString()),
					is_mall = int.Parse(oleDbDataReader["mall"].ToString()),
					actCmsRate = double.Parse(oleDbDataReader["actCmsRate"].ToString()),
					//actCmsRate = double.Parse(oleDbDataReader["actEarn"].ToString()),
					excellence = int.Parse(oleDbDataReader["excellence"].ToString()),
					startTime = int.Parse(oleDbDataReader["startTime"].ToString())
				});
			}
			string_2 = "";
			oleDbDataReader.Close();
			result = arrayList;
		}
		catch (Exception ex)
		{
			string_2 = "出错啦：" + ex.ToString();
			result = new ArrayList();
		}
		return result;
	}
	public ArrayList method_8(string string_1, out string string_2)
	{
		ArrayList result;
		try
		{
			ArrayList arrayList = new ArrayList();
			OleDbDataReader oleDbDataReader = new OleDbCommand(string_1, this.oleDbConnection_0).ExecuteReader();
			while (oleDbDataReader.Read())
			{
				arrayList.Add(new GoodsItem
				{
					num_iid = oleDbDataReader["itemId"].ToString()
				});
			}
			string_2 = "";
			oleDbDataReader.Close();
			result = arrayList;
		}
		catch (Exception ex)
		{
			string_2 = "出错啦：" + ex.ToString();
			result = new ArrayList();
		}
		return result;
	}
	public bool method_9(string string_1, out string string_2)
	{
		bool result;
		try
		{
			string text = "update bridgeitem set excellence=1 where eventId in({eventidlist});";
			new OleDbCommand(text.Replace("{eventidlist}", string_1), this.oleDbConnection_0).ExecuteNonQuery();
			string_2 = "";
			result = true;
		}
		catch (Exception ex)
		{
			string_2 = "出错啦！" + ex.ToString();
			result = false;
		}
		return result;
	}
}
